<title>添加文章 - QAdmin后台模板</title>


<body>


<!-- 配置文件 -->
<script type="text/javascript" src="./static/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="./static/ueditor/ueditor.all.js"></script>


<fieldset class="layui-elem-field layui-field-title">
    <legend>添加文章</legend>
</fieldset>


<form class="layui-form " action="">


    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <img class="pic_url" src="./static/image/pic.png" height="200px"/>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">缩略图</label>
        <div class="layui-input-inline">
            <input type="text" name="pic" id="pic_url" placeholder="不上传就留空" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-word-aux">
            <button type="button" class="layui-btn" id="pic">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
        </div>

    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline">
            <input type="text" name="title" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">优先级</label>
        <div class="layui-input-inline">
            <input type="text" name="sort" placeholder="" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">置顶时有效 数小靠前 不填为99</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分类</label>
        <div class="layui-input-inline" style="width: 200px">
            <select name="type">
                <option value="0">顶级分类</option>
                <option value="9">前端</option>
                <option value="11">&nbsp;&nbsp;&nbsp;html/css</option>
                <option value="16">&nbsp;&nbsp;&nbsp;javascript</option>
                <option value="20">&nbsp;&nbsp;&nbsp;jquery</option>
                <option value="15">&nbsp;&nbsp;&nbsp;vue</option>
                <option value="12">&nbsp;&nbsp;&nbsp;angular</option>
                <option value="25">&nbsp;&nbsp;&nbsp;小程序</option>
                <option value="13">后端</option>
                <option value="17">&nbsp;&nbsp;&nbsp;php</option>
                <option value="14">&nbsp;&nbsp;&nbsp;node.js</option>
                <option value="18">&nbsp;&nbsp;&nbsp;python</option>
                <option value="24">&nbsp;&nbsp;&nbsp;linux/shell</option>
                <option value="19">数据库</option>
                <option value="21">&nbsp;&nbsp;&nbsp;mysql</option>
                <option value="22">&nbsp;&nbsp;&nbsp;redis</option>
                <option value="23">&nbsp;&nbsp;&nbsp;mongodb</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block" style="width:1000px;">
            <script id="container" name="body" style="height: 500px" type="text/plain"></script>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">关键词</label>
        <div class="layui-input-inline">
            <input type="text" name="key" placeholder="用英文豆号隔开" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">附件地址</label>
        <div class="layui-input-inline">
            <input type="text" name="file" id="file_url" placeholder="不上传就留空 可使用外链http://" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-word-aux">
            <button type="button" class="layui-btn" id="file">
                <i class="layui-icon">&#xe67c;</i>在线上传
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否置顶</label>
        <div class="layui-input-block">
            <input type="checkbox" value="1" name="top" lay-text="开启|关闭" lay-skin="switch">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否显示</label>
        <div class="layui-input-block">
            <input type="checkbox" value="1" name="state" lay-text="开启|关闭" checked lay-skin="switch">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="submit">立即提交</button>

        </div>
    </div>
</form>

</body>


<script>
    var ue = UE.getEditor('container');
    setTimeout(function () {
        ue.setHeight(500)
    }, 500)
    layui.use(['form', 'upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload;


        upload.render({
            elem: '#file' //绑定元素
            , url: "/admin/uploads/file.html" //上传接口
            , done: function (res) {
                //上传完毕回调
                if (res.code == 1) {
                    $("#file_url").val(res.url);
                } else {
                    layer.msg(res.info, function () {
                    })
                }
            }, error: function () {
                layer.msg("上传异常");
            }
        });

        upload.render({
            elem: '#pic' //绑定元素
            , url: "/admin/uploads/pic.html" //上传接口
            , done: function (res) {
                //上传完毕回调
                if (res.code == 1) {
                    $("#pic_url").val(res.url);
                    $(".pic_url").attr("src", res.url);
                } else {
                    layer.msg(res.info, function () {
                    })
                }
            }, error: function () {
                layer.msg("上传异常");
            }
        });

        form.on('submit(submit)', function (data) {
            layer.load({time: 0});
            $.post(data.form.action, data.field, function (e) {
                layer.closeAll('loading');
                if (e.code == 1) {
                    layer.msg(e.msg, {icon: 1, shade: 0.5,});
                    setTimeout(function () {
                        window.location.href = e.url;
                    }, 1000);
                } else {
                    layer.msg(e.msg, {icon: 2, shade: 0.5, time: 2000, shadeClose: true});
                }
            })
            return false;
        });
    });
</script>

